package nosql

import (
	"errors"
	"gopkg.in/mgo.v2"
)

type MgbInstance struct {
	c  *mgo.Collection
	s  *mgo.Session
	db *mgo.Database
}

func NewMgbCollection(add string, dbname string, collection string) *MgbInstance {

	session, err := mgo.DialWithTimeout(add, 3)
	if err != nil {
		return nil
	}
	defer session.Close()
	c := session.DB(dbname).C(collection)

	return &MgbInstance{s: session, c: c}
}

func (collection *MgbInstance) Insert(data interface{}) error {

	if err := collection.c.Insert(data); err != nil {
		return errors.New("insert mongodb faild")
	}
	return nil
}

func (collection *MgbInstance) Upsert(key string, value string, data interface{}) error {

	return nil
}
